#include "datafrome.h"
#include "ui_datafrome.h"
#include <QDesktopServices>
#include <qdebug.h>

DataFrome::DataFrome(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DataFrome)
{
    ui->setupUi(this);
    connect(ui->urlLabel,SIGNAL(linkActivated(QString)),this,SLOT(openUrl(QString)));
}

DataFrome::DataFrome(QWidget *parent, DocumentDate data):QWidget(parent),ui(new Ui::DataFrome)
{
    ui->setupUi(this);
    connect(ui->urlLabel,SIGNAL(linkActivated(QString)),this,SLOT(openUrl(QString)));

    initData(data);
}

DataFrome::~DataFrome()
{
    delete ui;
}

void DataFrome::initData(DocumentDate data)
{
    ui->titleEdit->setText(data.title);
    QString urlStr = "";
    urlStr.sprintf("<a href=%s>%s<a/>",data.url.toStdString().c_str(),
                   data.url.toStdString().c_str());
    ui->urlLabel->setText(urlStr);
    ui->contentEdit->setText(data.content);
}

void DataFrome::openUrl(QString url)
{
    qDebug()<<"openurl";
    QDesktopServices::openUrl(QUrl(url));
}
